import '../../../data/user_profile_entity.dart';

/// 工作台数据模型
class WorkbenchModel {
  UserProfileEntity userProfile;
  final List<ActionCard> actionCards;
  final List<FunctionSection> functionSections;

  WorkbenchModel({
    required this.userProfile,
    required this.actionCards,
    required this.functionSections,
  });

  factory WorkbenchModel.fromJson(Map<String, dynamic> json) {
    return WorkbenchModel(
      userProfile: UserProfileEntity.fromJson(json['userProfile'] ?? {}),
      actionCards:
          (json['actionCards'] as List<dynamic>?)
              ?.map((e) => ActionCard.fromJson(e))
              .toList() ??
          [],
      functionSections:
          (json['functionSections'] as List<dynamic>?)
              ?.map((e) => FunctionSection.fromJson(e))
              .toList() ??
          [],
    );
  }
}

/// 操作卡片
class ActionCard {
  final String backgroud;
  final String title;
  final String icon;
  final String color;
  final Function? action;

  ActionCard({
    required this.backgroud,
    required this.title,
    required this.icon,
    required this.color,
    this.action,
  });

  factory ActionCard.fromJson(Map<String, dynamic> json) {
    return ActionCard(
      backgroud: json['index'] ?? '',
      title: json['title'] ?? '',
      icon: json['icon'] ?? '',
      color: json['color'] ?? '',
      action: json['action'] ?? '',
    );
  }
}

/// 功能分区
class FunctionSection {
  final String title;
  final List<FunctionItem> items;

  FunctionSection({required this.title, required this.items});

  factory FunctionSection.fromJson(Map<String, dynamic> json) {
    return FunctionSection(
      title: json['title'] ?? '',
      items:
          (json['items'] as List<dynamic>?)
              ?.map((e) => FunctionItem.fromJson(e))
              .toList() ??
          [],
    );
  }
}

/// 功能项
class FunctionItem {
  final String id;
  final String title;
  final String icon;
  final int unreadCount;
  final Function? action;

  FunctionItem({
    required this.id,
    required this.title,
    required this.icon,
    required this.unreadCount,
    this.action,
  });

  factory FunctionItem.fromJson(Map<String, dynamic> json) {
    return FunctionItem(
      id: json['id'] ?? '',
      title: json['title'] ?? '',
      icon: json['icon'] ?? '',
      unreadCount: json['unreadCount'] ?? 0,
      action: json['action'] ?? '',
    );
  }
}
